<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改药品')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-cai-edit" th:object="${yao}">
		<input name="yaoId" id="yaoId" type="hidden" th:field="*{yaoId}" />
		<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
		<div class="form-group">
			<label class="col-sm-3 control-label ">上级药品分类：</label>
			<div class="col-sm-8">
				<div class="input-group">
					<input class="form-control" type="text" id="treeName" onclick="selectYaoTree()" readonly="true" th:field="*{parentName}">
					<span class="input-group-addon"><i class="fa fa-search"></i></span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">药品名称：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="yaoName" th:field="*{yaoName}" id="yaoName" required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">药品编码：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="code" th:field="*{code}" id="code" required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">显示排序：</label>
			<div class="col-sm-8">
				<input class="form-control" type="text" name="orderNum" th:field="*{orderNum}" required>
			</div>
		</div>


	</form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "system/ncYaoClass";

    $("#form-cai-edit").validate({
        onkeyup: false,
        rules:{
            caiName:{
                remote: {
                    url: prefix + "/checkYaoNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "caiId": function() {
                            return $("#yaoId").val();
                        },
                        "parentId": function() {
                            return $("input[name='parentId']").val();
                        },
                        "yaoName": function() {
                            return $.common.trim($("#yaoName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            orderNum:{
                digits:true
            },
            email:{
                email:true,
            },
            phone:{
                isPhone:true,
            },
        },
        messages: {
            "yaoName": {
                remote: "药品已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-cai-edit').serialize());
        }
    }

    /*蔬菜管理-修改-选择蔬菜树*/
    function selectYaoTree() {
        var caiId = $("#treeId").val();
        if(caiId > 0) {
            var options = {
                title: '药品选择',
                width: "380",
                url: prefix + "/selectYaoTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        } else {
            $.modal.alertError("父药品不能选择");
        }
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowLastLevel(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
